package com.lishe.lishe.lishe.module.excitation.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.MyRecyclerView.RecyclerviewBaseAdapter;
import com.lishe.lishe.lishe.module.excitation.bean.MineExcitationObject;

import java.util.List;

/**
 * Created by DELL on 2017/10/26.
 */

public class MineExcitationListAdapter extends RecyclerviewBaseAdapter implements View.OnClickListener {

    private Activity mContext;
    private List<MineExcitationObject> mList;
    public MineExcitationListAdapter(Activity context, List<MineExcitationObject> list){
        this.mContext=context;
        this.mList=list;
    }

    @Override
    public MyViewHolder onCreateViewHolderMy(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_mine_excitation,null);
        MyViewHolder holder=new MyViewHolder(view);
        view.setOnClickListener(this);
        return holder;
    }

    @Override
    public void onBindViewHolderMy(RecyclerView.ViewHolder holder, int position) {
        MineExcitationObject object=mList.get(position);
        if(!TextUtils.isEmpty(object.getGiftId())){//是否需要显示文字
            ((MyViewHolder)holder).text.setVisibility(View.VISIBLE);
            ((MyViewHolder)holder).background.setVisibility(View.GONE);
            ((MyViewHolder)holder).text.setText("x"+String.valueOf(object.getNum()));
            ImageLoaderUtils.displayImage(mContext, object.getGiftImgUrl(),((MyViewHolder) holder).img);
        }

        if(!TextUtils.isEmpty(object.getAchieveId())){
            ((MyViewHolder)holder).text.setVisibility(View.GONE);
            if (TextUtils.isEmpty(object.getAchievedTime()) && (TextUtils.isEmpty(object.getUserId())||object.getUserId().equals("0"))) {//没有时间和userId,表明成就未获得
                ((MyViewHolder) holder).background.setVisibility(View.VISIBLE);
            }else{
                ((MyViewHolder) holder).background.setVisibility(View.GONE);
            }
            ImageLoaderUtils.displayRoundImage(mContext, object.getAchieveImg(),((MyViewHolder) holder).img, R.drawable.defalut_img);
        }

    }

    @Override
    public int getItemCountMy() {
        return mList.size();
    }

    @Override
    public int getItemViewTypeMy(int position) {
        return 0;
    }

    @Override
    public void onClick(View v) {

    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView img,background;
        private TextView text;

        public MyViewHolder(View itemView) {
            super(itemView);
            img=itemView.findViewById(R.id.img);
            text=itemView.findViewById(R.id.text);
            background=itemView.findViewById(R.id.background);
        }
    }
}
